local joy__qiangjinjiu = fk.CreateSkill {

  name = "joy__qiangjinjiu",

  tags = {  },

}



joy__qiangjinjiu:addEffect(fk.EventPhaseStart, {
  name = "joy__qiangjinjiu",
  events = {fk.EventPhaseStart},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(joy__qiangjinjiu.name) and target ~= player and target.phase == Player.Start and not player:isKongcheng()
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 1, 1, false, joy__qiangjinjiu.name, true, ".", "#joy__qiangjinjiu-invoke:"..target.id, true)
    if #cards > 0 then
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self), joy__qiangjinjiu.name, player, player)
    if player.dead or target.dead then return end
    local choice = room:askForChoice(player, {"joy__qiangjinjiu_choice1", "joy__qiangjinjiu_choice2"}, joy__qiangjinjiu.name)
    if choice:endsWith("1") then
      local throw = target:getCardIds("e")
      if #throw > 0 then
        room:throwCard(throw, joy__qiangjinjiu.name, target, player)
      end
      if not target.dead then
        local cards = room:getCardsFromPileByRule("analeptic")
        if #cards > 0 then
          room:moveCardTo(cards, Card.PlayerHand, target, fk.ReasonPrey, joy__qiangjinjiu.name, nil, true)
        end
      end
    else
      local cards = table.filter(target:getCardIds("h"), function(id) return Fk:getCardById(id).name == "analeptic" end)
      if #cards == 0 and not target:isNude() then
        cards = {room:askForCardChosen(player, target, "he", joy__qiangjinjiu.name)}
      end
      if #cards > 0 then
        room:moveCardTo(cards,Card.PlayerHand,player,fk.ReasonPrey,joy__qiangjinjiu.name,nil,false,player)
      end
    end
  end,
})

return joy__qiangjinjiu